@extends('admin.main')

@section('body')
    <div class="main-title">
        <h2>配置管理 [ @if(isset($_GET['group']))
                <a href="{{urlAdmin('config','getIndex')}}">全部</a>
            @else
                <strong>全部</strong>
            @endif
            @if(count(C('CONFIG_GROUP_LIST')))
                @foreach(C('CONFIG_GROUP_LIST') as $k => $v)
                    @if(request('group',0) != $k)
                        <a href="{{urlAdmin('config','getIndex',['group'=>$k])}}">{{$v}}</a>
                    @else
                        <strong>{{$v}}</strong>
                    @endif
                @endforeach
            @endif
            &nbsp;]
        </h2>
    </div>

    <div class="cf">
        <a class="btn" href="{{urlAdmin('config','getAdd')}}">新 增</a>
        <a class="btn" href="javascript:;">删 除</a>
        <button class="btn list_sort" url="{{urlAdmin('config','getSort',['group'=>request('group')])}}">排序</button>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" name="name" class="search-input" value="{{request('name')}}" placeholder="请输入配置名称">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlAdmin('config','getIndex')}}"><i class="btn-search"></i></a>
            </div>
        </div>
    </div>

    <div class="data-table table-striped">
        <table>
            <thead>
            <tr>
                <th class="row-selected">
                    <input class="checkbox check-all" type="checkbox">
                </th>
                <th>ID</th>
                <th>名称</th>
                <th>标题</th>
                <th>分组</th>
                <th>类型</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        <td><input class="ids" type="checkbox" name="ids[]" value="{{$v['id']}}" /></td>
                        <td>{{$v['id']}}</td>
                        <td><a href="{{urlAdmin('config','getEdit',['id'=>$v['id']])}}">{{$v['name']}}</a></td>
                        <td>{{$v['title']}}</td>
                        <td>{{get_config_group($v['group'])}}</td>
                        <td>{{get_config_type($v['type'])}}</td>
                        <td>
                            <a title="编辑" href="{{urlAdmin('config','getEdit',['id'=>$v['id']])}}">编辑</a>
                            <a class="confirm ajax-get" title="删除" href="{{urlAdmin('config','getDel',['id'=>$v['id']])}}">删除</a>
                        </td>
                    </tr>
                @endforeach
            @else
                <td colspan="6" class="text-center">aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
        <!-- 分页 -->
        <div class="page">
            @if($rows['last_page']>1)
                <div>
                    @if($rows['prev_page_url'])
                        <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                    @endif
                    @if(count($rows['pageNoList']))
                        @foreach($rows['pageNoList'] as $v)
                            @if($rows['current_page'] == $v)
                                <span class="current">{{$v}}</span>
                            @else
                                <a class="num" href="{{urlAdmin('config','getIndex',['page'=>$v])}}">{{$v}}</a>
                            @endif
                        @endforeach
                    @endif
                    @if($rows['next_page_url'])
                        <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                    @endif
                    <span class="rows">共 {{$rows['total']}} 条记录</span>
                </div>
            @endif
        </div>
    </div>
@endsection

@section('script')
    <script type="text/javascript">
        $(function () {
            //搜索功能
            $("#search").click(function () {
                var url = $(this).attr('url');
                var query = $('.search-form').find('input').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
                query = query.replace(/^&/g, '');
                if (url.indexOf('?') > 0) {
                    url += '&' + query;
                } else {
                    url += '?' + query;
                }
                window.location.href = url;
            });
            //回车搜索
            $(".search-input").keyup(function (e) {
                if (e.keyCode === 13) {
                    $("#search").click();
                    return false;
                }
            });
            //点击排序
            $('.list_sort').click(function () {
                var url = $(this).attr('url');
                var ids = $('.ids:checked');
                var param = '';
                if (ids.length > 0) {
                    var str = new Array();
                    ids.each(function () {
                        str.push($(this).val());
                    });
                    param = str.join(',');
                }

                if (url != undefined && url != '') {
                    window.location.href = url + '&ids=' + param;
                }
            });
        });
    </script>
@endsection